package com.fc.v2.service;

import java.util.List;
import java.util.Arrays;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import cn.hutool.core.util.StrUtil;
import com.fc.v2.common.base.BaseService;
import com.fc.v2.common.support.ConvertUtil;
import com.fc.v2.mapper.auto.MybatisTestMapper;
import com.fc.v2.model.auto.MybatisTest;
import com.fc.v2.model.auto.MybatisTestExample;
import com.fc.v2.model.custom.Tablepar;
import com.fc.v2.util.SnowflakeIdWorker;
import com.fc.v2.util.StringUtils;

/**
 * 自动生成测试 MybatisTestService
 * @Title: MybatisTestService.java 
 * @Package com.fc.v2.service 
 * @author fuce_自动生成
 * @email ${email}
 * @date 2023-10-12 09:56:08  
 **/
@Service
public class MybatisTestService implements BaseService<MybatisTest, MybatisTestExample>{
	@Autowired
	private MybatisTestMapper mybatisTestMapper;
	
	
	/**
	 * 分页查询
	 * @param pageNum
	 * @param pageSize
	 * @return
	 */
	 public PageInfo<MybatisTest> list(Tablepar tablepar,MybatisTest mybatisTest){
	        MybatisTestExample testExample=new MybatisTestExample();
			//搜索
			if(StrUtil.isNotEmpty(tablepar.getSearchText())) {//小窗体
	        	testExample.createCriteria().andLikeQuery2(tablepar.getSearchText());
	        }else {//大搜索
	        	testExample.createCriteria().andLikeQuery(mybatisTest);
	        }
			//表格排序
			//if(StrUtil.isNotEmpty(tablepar.getOrderByColumn())) {
	        //	testExample.setOrderByClause(StringUtils.toUnderScoreCase(tablepar.getOrderByColumn()) +" "+tablepar.getIsAsc());
	        //}else{
	        //	testExample.setOrderByClause("id ASC");
	        //}
	        PageHelper.startPage(tablepar.getPage(), tablepar.getLimit());
	        List<MybatisTest> list= mybatisTestMapper.selectByExample(testExample);
	        PageInfo<MybatisTest> pageInfo = new PageInfo<MybatisTest>(list);
	        return  pageInfo;
	 }

	@Override
	public int deleteByPrimaryKey(String ids) {
		
			List<String> lista=ConvertUtil.toListStrArray(ids);
			MybatisTestExample example=new MybatisTestExample();
			example.createCriteria().andIdIn(lista);
			return mybatisTestMapper.deleteByExample(example);
			
		
	}
	
	
	@Override
	public MybatisTest selectByPrimaryKey(String id) {
		
			return mybatisTestMapper.selectByPrimaryKey(id);
		
	}

	
	@Override
	public int updateByPrimaryKeySelective(MybatisTest record) {
		return mybatisTestMapper.updateByPrimaryKeySelective(record);
	}
	
	
	/**
	 * 添加
	 */
	@Override
	public int insertSelective(MybatisTest record) {
		
		//添加雪花主键id
		record.setId(SnowflakeIdWorker.getUUID());
			
		
		return mybatisTestMapper.insertSelective(record);
	}
	
	
	@Override
	public int updateByExampleSelective(MybatisTest record, MybatisTestExample example) {
		
		return mybatisTestMapper.updateByExampleSelective(record, example);
	}

	
	@Override
	public int updateByExample(MybatisTest record, MybatisTestExample example) {
		
		return mybatisTestMapper.updateByExample(record, example);
	}

	@Override
	public List<MybatisTest> selectByExample(MybatisTestExample example) {
		
		return mybatisTestMapper.selectByExample(example);
	}

	
	@Override
	public long countByExample(MybatisTestExample example) {
		
		return mybatisTestMapper.countByExample(example);
	}

	
	@Override
	public int deleteByExample(MybatisTestExample example) {
		
		return mybatisTestMapper.deleteByExample(example);
	}
	
	/**
	 * 修改权限状态展示或者不展示
	 * @param mybatisTest
	 * @return
	 */
	public int updateVisible(MybatisTest mybatisTest) {
		return mybatisTestMapper.updateByPrimaryKeySelective(mybatisTest);
	}


}
